<template>
    <div>
    <h1>公告显示页面</h1>
    名称<input type="text" v-model="page.name">
    <select v-model="page.types">
                    <option value="0">请选择</option>
                    <option v-for="s in tytpes" :value="s.typeid">{{s.typename}}</option>
                </select>
                <input  type="button" value="查询" @click="cha">
    <table>
        <thead>
            <tr>
                <td><input type="checkbox" @change="quan"  v-model="sells"></td>
                <td>名称</td>
                <td>时间</td>
                <td>内容</td>
                <td>状态</td>
                <td>类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="m in data">
                <td><input type="checkbox" :value="m.gid"  v-model="lidstringss"></td>
                <td>{{m.gname}}</td>
                <td>{{m.gtime.substr(0,10)}}</td>
                <td>{{m.gstates?"启用":"禁用"}}</td>
                <td>{{m.grong}}</td>
                <td>{{m.typename}}</td>
                <td>操作</td>
            </tr>
        </tbody>
    </table>
    </div>
    <input  type="button" value="首页" @click="Fanye(1)">
    <input  type="button" value="上一页" @click="Fanye(2)">
    <input  type="button" value="下一页" @click="Fanye(3)">
    <input  type="button" value="尾页" @click="Fanye(4)">
    一共{{paga.pcount}}页,一共{{paga.count}}行，每页{{page.size}}行，当前第{{page.index}}页
    <input  type="button" value="批量修改状态" @click="piupdatesates">
    <input  type="button" value="批量逻辑删除" @click="piluoDel">
    <input  type="button" value="批量逻辑删除" @click="pilDel">

</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const sells=ref(false);
const lidstringss=ref([0]);

const quan=()=>
{
    if(sells.value)
{
    for(var i=0;i<data.value.length;i++)
{
    lidstringss.value.push(data.value[i].gid);
}
}
else{
    lidstringss.value=[0]
}
}


const data=ref([{
    
    "gid": 0,
    "gname": "",
    "gtime": "",
    "grong": "",
    "typeid": 0,
     "typename": "",
     "gstates": null
  
  }])

const cha=()=>
{
    page.value.index=1;
    Getdata();
}



  const Fanye=(vid:any)=>
  {
   if(vid==1)
   {
    page.value.index=1;
    Getdata();
   }
   if(vid==2)
   {
    if( page.value.index>1)
   {
    page.value.index-=1;
    Getdata();
   }
    
   }
   if(vid==3)
   {
    if(page.value.index<paga.value.pcount)
    page.value.index+=1;
    Getdata();
   }

   if(vid==4)
   {
    page.value.index=paga.value.pcount;
    Getdata();
   }

  }

  onMounted(()=>
{
    getate();
    Getdata()
})
const tytpes=ref([{

"typeid": 0,
"typename": ""
}

])
const getate=()=>
{
    axios.get("https://localhost:7075/api/type/xia").then(res=>
        {
            tytpes.value=res.data;
        }
    )
}
const page=ref({
    index:1,
    size:3,
    name:"",
    types:null
})
const paga=ref({
    count:0,
    pcount:0
})



const Getdata=()=>
{
    axios.get("https://localhost:7075/api/gong/fen",{params:page.value}).then(res=>
        {
            data.value=res.data.data;
            paga.value.count=res.data.count;
            paga.value.pcount=Math.ceil( paga.value.count/page.value.size);

        }
    )
}


const piupdatesates=()=>
{
  axios.get("https://localhost:7075/api/gong/piupdate",{params:{idssing:lidstringss.value.toString()}}).then(res=>
{
    if(res.data>0)
{
    alert("状态修改成功");
    Getdata()
}
else

{
    alert("状态修改失败")
}
}
  )
}
const piluoDel=()=>
{
    if(confirm("确定要删除吗"))
{
    axios.delete("https://localhost:7075/api/gong/piluoDel",{params:{idssing:lidstringss.value.toString()}}).then(res=>
{
    if(res.data>0)
{
    alert("逻辑删除成功");
    Getdata()
}
else

{
    alert("逻辑删除失败")
}
}
  )

}

}

const pilDel=()=>
{
    if(confirm("确定要删除吗"))
{
    axios.delete("https://localhost:7075/api/gong/piDel",{params:{idssing:lidstringss.value.toString()}}).then(res=>
{
    if(res.data>0)
{
    alert("删除成功");
    Getdata()
}
else

{
    alert("删除失败")
}
}
  )

}

}
</script>

<style scoped>

</style>